/**
 * 
 */
package com.java.test.util;

import java.util.List;

 
/**
 * @author Administrator 后台分页对象
 * @param <T>
 */
public class PageInfo<T> {

	// 请求数据
	private T info;

	/**
	 * 当前页
	 */
	private int currentPage;
	/**
	 * 每页显示条数
	 */
	private int pageCount;
	/**
	 * 总条数
	 */
	private int totalCount;
	/**
	 * 总页数
	 */
	private int totalPage;
	/**
	 * 分页查询的数据
	 */
	private List<T> list;

	public PageInfo() {
		super();
	}

	public PageInfo(int currentPage, int pageCount, int totalCount) {
		this.currentPage = currentPage;
		this.pageCount = pageCount;
		this.totalCount = totalCount;

		// 如果没有指定当前查哪页, 则默认查第1页
		if (currentPage == 0) {
			this.currentPage = 1;
		}
		// 如果没有指定每页多少条数据, 则默认为5条
		if (pageCount == 0) {
			this.pageCount = 5;
		}
		// 获取总页数
		this.totalPage = (int) Math.ceil(1.0 * this.totalCount / this.pageCount);
		// 当前页不能小于1
		if (this.currentPage < 1) {
			this.currentPage = 1;
		}
		// 当前页不能大于总页数
		if (this.currentPage > this.totalPage && this.totalPage != 0) {
			this.currentPage = this.totalPage;
		}
	}

	public T getInfo() {
		return info;
	}

	public void setInfo(T info) {
		this.info = info;
	}

	/**
	 * 获取分页查询的起始参数
	 * 
	 * @return
	 */
	public int getStart() {
		return (this.currentPage - 1) * this.pageCount;
	}

	public int getCurrentPage() {
		return currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	public int getPageCount() {
		return pageCount;
	}

	public void setPageCount(int pageCount) {
		this.pageCount = pageCount;
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	
	

	public List<T> getList() {
		return list;
	}

	public void setList(List<T> list) {
		this.list = list;
	}

}
